package com.xiaohao.communication.service;

import com.mongodb.BasicDBObject;
import com.mongodb.client.result.DeleteResult;
import com.xiaohao.communication.bean.Answer;
import com.xiaohao.communication.bean.PraiseDetails;
import com.xiaohao.communication.bean.UserTopic;
import com.xiaohao.communication.dao.UserTopicPageDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserTopicService  {

    @Autowired
    UserTopicPageDao userTopicDao;

    //发布话题
    public void publishTopic(UserTopic userTopic){
        userTopicDao.publishTopic(userTopic);
    }




    //删除话题
    public void deleteTopic(int id){
        userTopicDao.deleteTopic(id);
    }



    //发布回答
    public void publihAnswer(Answer answer) {
        userTopicDao.publihAnswer(answer);
    }

    //删除回答
    public void deleteAnswer(int id) {
        userTopicDao.deleteAnswer(id);
    }


    /***********************************/

    //点赞

    public void addPraise(PraiseDetails praiseDetails) {
        userTopicDao.addPraise(praiseDetails);
    }

    //取消赞

    public void deletePraise(int topic_id) {
        userTopicDao.deletePraise(topic_id);
    }

    //模糊查询话题

    public List<UserTopic> getUserTopic(String content) {
        List<UserTopic> userTopic = userTopicDao.getUserTopic(content);
        return userTopic;
    }

    //获取的当前话题所有回答
    public List<Answer> getCurrTopicAllAnswer(int topic_id) {
        List<Answer> currTopicAllAnswer = userTopicDao.getCurrTopicAllAnswer(topic_id);
        return currTopicAllAnswer;
    }

    //获取所有话题
    public List<UserTopic> getAllUserTopic() {

        List<UserTopic> allUserTopic = userTopicDao.getAllUserTopic();
        return allUserTopic;

    }


    //根据话题ID获取话题信息
    public UserTopic getTopicByTopicId(int topic_id) {
        UserTopic userTopic = userTopicDao.getTopicByTopicId(topic_id);
        return userTopic;
     }
}
